#ifndef YKTHREADPROCIMG_H
#define YKTHREADPROCIMG_H

#include <QThread>
#include "DPGMTracking.h"

#define DEFAULT_WIDTH 1024
#define DEFAULT_HEIGHT 1024

class DPGMTracking;
class YK16GrayImage;

using namespace std;

class YKThreadProcImg : public QThread
{ 
public:
	DPGMTracking* m_pParent;
  int m_iCrntIdx;
  int m_iNumProj;

  //unsigned short** m_pArrData; //
  //single YKimage, in this step.
  YK16GrayImage* m_pYKImageProc; //will be image array for real time volumetric image processing  
  YK16GrayImage* m_pYKImageROIProc;

  //FLEXDATA : coming with YKImage
  // m_vRefMarkerPosDCM // should be copied from Main
  //RefPoints 2D will be calculated here

  double m_fOffsetLat;
  double m_fOffsetVert;
  double m_fOffsetSI;

  float m_fMVGanAngle;
  float m_fPanelShiftX;
  float m_fPanelShiftY;
  bool m_bKVOn;
  bool m_bMVOn;
  //int m_iDispMarker;
  //int m_iNumOfTrackMarker;
  //m_arrYKImage[curIdx].m_iNumOfDispMarker = ui.lineEditNumOfMarkerDisp->text().toInt();
  //m_arrYKImage[curIdx].m_iNumOfTrackMarker = ui.lineEditNumOfMarkerTrack->text().toInt();

  IMGPROC_PARAMSET m_paramset; 


  float m_fThreMultiplySD;
  float m_iSameMarkerMargin;

  int m_iCandidate;
//  int iNumOfTrackMarker = ui.lineEditNumOfMarkerTrack->text().toInt();
  double m_motionW_X;
  double m_motionW_Y;
  double m_CC_weighting;

  //int m_iMarginLt, m_iMarginTop, m_iMarginRt, m_iMarginBottom;	 
  QString m_strMargin;
	  
  vector<QPoint> m_vPrevFrameMarkerPosProc;
  vector<VEC3D> m_vRefMarkerPosDCMProc;
  QString m_strCommand;

  UnsignedShortImageType::Pointer m_spSrcImage;
  UnsignedShortImageType::Pointer m_spCCTemplate;//2D template


public:
//  YKThreadProcImg(ElektaTracking* pParent);
	//YKThreadProcImg(DPGMTracking* pParent, int iCrntIdx, float fMVGanAngle, float fPanelShiftX, float fPanelShiftY, int iNumProj);	

	YKThreadProcImg(DPGMTracking* pParent, int iCrntIdx, float fMVGanAngle, float fPanelShiftX, float fPanelShiftY, bool bKVOn, bool bMVOn, int iNumProj);
  ~YKThreadProcImg();  

  void CopyDataFromMain();

  void run();  
  void CreateTemplate(int sizeX, int sizeY, float spacingX, float spacingY);


  QPoint Get2DPosFromDCM3D(float DCM_X, float DCM_Y, float DCM_Z, float MV_GanAngle, float panelOffsetX, float panelOffsetY, float fSAD, float fSID, float width2D, float height2D, float spX, float spY);



  void FillCurrentROI(YK16GrayImage* pYKImageFull, YK16GrayImage* pYKImageROI); //should be called after ResetROIExt
  /*void GaussianSmoothing(double fSigma);
  void IntensityWindowing(int srcMin, int srcMax, int tarMin, int tarMax);
  void FirstDerivative_Y(int threPercent);
  void FirstDerivative_Y_Line(int threPercent);
  void SobelEdgeDetection(int threPercent, YK16GrayImage* pYKImageROI);
  void BinaryImage(int threshold);
  void MedianFiltering(int winSize);*/
  void FFT_NormalizedCrossCorrelation(YK16GrayImage* pYKImageROI, int iReqNumOverlapPix);

  //void ImgProcessingForROI(YK16GrayImage* pYKImage, YK16GrayImage* pYKImageROI);
  void ImgProcessingForROI(YK16GrayImage* pYKImage, YK16GrayImage* pYKImageROI, IMGPROC_PARAMSET& stParamset);	

  void ResetROIExt(YK16GrayImage* pYKImage, int marginLt, int marginTop, int marginRt, int marginBottom); //for current image only  
  void FindMarkerInROI_A(YK16GrayImage* pImageYKFull, YK16GrayImage* pImageYKCurROI, vector<PIXINFO>& vOutputMarkerWithCC, float fThreMultiplySD, float sameMarkerMargin);

  double FindMarkerInROI_B(YK16GrayImage* pImageYKFull, YK16GrayImage* pImageYKCurROI,
	  vector<PIXINFO>& vInputMarkerWithCC, int iCandidate, int iNumOfTrackMarker,
	  double motionW_X, double motionW_Y, double CC_weighting, vector<QPoint>& vPrevFrameMarkerPos);


  void Combination(std::vector<int>& vIndex, int combCnt, std::vector<int>& vOutputComb);

  double ComputeMinVecDiffAndSortIndex(vector<int>& vCurCompIndex, vector<QPoint>& vMarkerPosRef, vector<QPoint>& vMarkerPosComp);
  double GetMeanVecDiff(vector<QPoint>& vMarkerPosRef, vector<QPoint>&vMarkerPosComp);

};

#endif // YKTHREADPROCIMG_H
